package com.xyu.gulimall.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;


import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GlimallCorsConfiguration {
    @Bean
    public CorsWebFilter corsWebFilter(){
        //创建跨域资源
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //配置跨域
        //请求头*允许所有
        corsConfiguration.addAllowedHeader("*");
        //请求方法
        corsConfiguration.addAllowedMethod("*");
        // 请求来源
        corsConfiguration.addAllowedOriginPattern("*");
        //是否允许携带Cookie进行跨域
        corsConfiguration.setAllowCredentials(true);
        source.registerCorsConfiguration("/**",corsConfiguration);// /**任意路径都进行跨域
        return new CorsWebFilter(source);
    }
}
